package com.xiyun.f301t400;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class IntersectionOfTwoArr_350 {
    class Solution {
        public int[] intersect(int[] nums1, int[] nums2) {
            List<Integer> list = new ArrayList<>();
            for (int j : nums1) {
                for (int i1 = 0; i1 < nums2.length; i1++) {
                    if (nums2[i1] == -1) {
                        continue;
                    }
                    if (j == nums2[i1]) {
                        nums2[i1] = -1;
                        list.add(j);
                        break;
                    }
                }
            }
            int[] arr = new int[list.size()];
            int index = 0;
            for (Integer integer : list) {
                arr[index++] = integer;
            }
            return arr;
        }
    }

    public static void resolve(String[] args) {
        int[] nums1 = {4,9,5}, nums2 = {9,4,9,8,4};
        Solution solution = new IntersectionOfTwoArr_350().new Solution();
        System.out.println(Arrays.toString(solution.intersect(nums1, nums2)));
    }
}
/*执行用时：
3 ms
, 在所有 Java 提交中击败了
38.84%
的用户
内存消耗：
41.3 MB
, 在所有 Java 提交中击败了
69.88%
的用户*/
